@extends('admin::layouts.master')
@section('title')
    结算列表
@endsection
@section('tab')
    <div id="refuse_settle_html" style="display:none;">
        <form class="layui-form" lay-filter="refuse_settle_form">
            <div class="layui-form-item">
                <label for="L_name" class="layui-form-label">
                    <span class="x-red">*</span>驳回原因</label>
                <div class="layui-input-inline">
                    <input type="text" id="L_name" name="reason" required="" lay-verify=""  autocomplete="off" class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label for="L_repass" class="layui-form-label"></label>
                <input type="hidden" id="L_id" name="id">
                <button class="layui-btn"   lay-filter="refuse_settle_form_submit" lay-submit="">驳回</button>
            </div>
        </form>
    </div>

    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-input-inline layui-show-xs-block">
                                <a class="layui-btn" onclick="location.reload()">
                                    <i class="layui-icon layui-icon-refresh"></i>
                                </a>
                            </div>
                        </form>
                    </div>

                    <div class="layui-card-body layui_overflow_y ">
                        <table class="layui-table layui-form">
                            <thead>
                            <tr>
                                <th>编号</th>
                                <th>商户名称</th>
                                <th>打款账户信息</th>
                                <th>收款账户信息</th>
                                <th>结算证明</th>
                                <th>结算总额</th>
                                <th>实际转账总额</th>
                                <th>手续费率</th>
                                <th>提交时间</th>
                                <th>结算时间</th>
                                <th>状态</th>
{{--                                <th>原因</th>--}}
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(!empty($data))
                            @foreach($data as $key=>$value)
                                <tr>
                                    <td>{{$key+1}}</td>
                                    <td>{{$value['shop']['name']}}</td>
                                    <td>
                                        @if($value['out_account_type'] === 'ali')
                                            支付宝账号：{{$value['out_ali_account']}}<br/>
                                            户主姓名：{{$value['out_ali_account_realname']}}<br/>
                                        @endif

                                        @if($value['out_account_type'] === 'bank')
                                            银行名称：{{$value['out_bank']}}<br/>
                                            支行名称：{{$value['out_bank_branch']}}<br/>
                                            银行卡号：{{$value['out_bank_card']}}<br/>
                                            户主姓名：{{$value['out_bank_card_realname']}}<br/>
                                        @endif
                                    </td>
                                    <td>
                                        @if($value['in_account_type'] === 'ali')
                                            支付宝账号：{{$value['in_ali_account']}}<br/>
                                            户主姓名：{{$value['in_ali_account_realname']}}<br/>
                                        @endif

                                        @if($value['in_account_type'] === 'bank')
                                            银行名称：{{$value['in_bank']}}<br/>
                                            支行名称：{{$value['in_bank_branch']}}<br/>
                                            银行卡号：{{$value['in_bank_card']}}<br/>
                                            户主姓名：{{$value['in_bank_card_realname']}}<br/>
                                        @endif
                                    </td>
                                    <td>
                                        @if(empty($value['settle_testify_img']))

                                        @else
                                            <img src="{{$value['settle_testify_img']}}" style="width: 80px;height: 80px;" class="Look_img" title="点击查看大图" >
                                        @endif
                                    </td>
                                    <td>{{$value['settle_money']}}</td>
                                    <td>{{$value['transfer_account_money']}}</td>
                                    <td>{{$value['service_fee_rate']}}</td>
                                    <td>{{$value['submit_time']}}</td>
                                    <td>{{$value['settle_time']}}</td>
                                    <td>
                                        @switch($value['state'])
                                            @case(1)
                                            待提交
                                            @break

                                            @case(2)
                                            待结算
                                            @break

                                            @case(3)
                                            已结算
                                            @break

                                            @default
                                            无
                                        @endswitch
                                    </td>
{{--                                    <td>{{$value['reason']}}</td>--}}
                                    <td class="td-manage">
                                        @if($value['state'] === 2)
                                            <button class="layui-btn layui-btn layui-btn-xs"  onclick="xadmin.open('确认结算','{{route("admin_account_settle_coupon_confirm_page",["id"=>$value["id"]])}}')" >确认结算</button>
                                        <?php $json_value = json_encode($value);?>
                                            <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="refuse_settle({{$json_value}})" >驳回结算</button>
                                        @else
                                            <button class="layui-btn layui-btn layui-btn-xs layui-btn-disabled" >提交结算</button>
                                            <button class="layui-btn-danger layui-btn layui-btn-xs layui-btn-disabled" >驳回结算</button>
                                        @endif


{{--                                        <a title="编辑" onclick="xadmin.open('编辑','{{route('shop_account_settle_edit_page',['id'=>$value['id']])}}')" href="javascript:;">--}}
{{--                                            <i class="layui-icon"></i>--}}
{{--                                        </a>--}}
                                    </td>
                                </tr>
                            @endforeach
                            @else
                                <td colspan="66" align="center">暂无数据</td>
                            @endif
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{$page_data['page_link']}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

@endsection

@section('tab_js')
    <script>
        layui.use(['layer', 'jquery'], function () {
            $ = layui.jquery;
            var layer = layui.layer;

            //点击图片查看大图
            var bigImgIndex = null;
            $("body").on('click','.Look_img',function(){
                var img_src = $(this).attr('src');
                var img_infor = "<img border='0' src='" + img_src + "' />";
                bigImgIndex = layer.open({
                    content:img_infor,
                    type:1,
                    area:['auto'],
                    shadeClose: true,
                    shade:[0.4, '#000000'],
                    title:false,
                    closeBtn:true
                });
            });


        })

        /*驳回结算*/
        function refuse_settle(settle_data) {

            var temp_html = layer.open({
                type: 1,
                content:$("#refuse_settle_html") //这里content是一个普通的String
            });
            layui.use(['form', 'layer','jquery'],
                function() {
                    $ = layui.jquery;
                    var form = layui.form,
                        layer = layui.layer;

                    //初始化表单数据值
                    form.val('refuse_settle_form', {
                        id:settle_data.id,
                        reason:'',
                    });

                    //监听提交
                    form.on('submit(refuse_settle_form_submit)',
                        function(data) {
                            var $_data = data.field;
                            if($_data.reason.length <= 0){
                                layer.msg('请填写驳回原因');
                                return false;
                            }
                            // console.log($_data);
                            // return false;


                            var $_url = '{{route('admin_account_settle_coupon_refuse_settle')}}';
                            $.ajax({
                                url:$_url,
                                type:'post',
                                data:$_data,
                                dataType : "json",
                                success:function(result){
                                    if(result.state === 0){

                                        layer.msg(
                                            "操作成功",
                                            {time:500,icon: 6},
                                            function() {
                                                //关闭当前frame
                                                layer.close(temp_html);
                                                location.reload();
                                            });

                                    }else{
                                        layer.msg(result.msg, {time:2000,icon: 5});
                                    }

                                }});
                            return false;

                        });
                    //添加同级权限表单初始赋值


                });

        }

    </script>

@endsection




